package com.ruoyi.shop.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.shop.domain.SysAliRole;
import com.ruoyi.shop.service.ISysAliRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 阿里登录角色绑定Controller
 *
 * @author yanghua
 * @date 2020-10-13
 */
@RestController
@RequestMapping("/alirole")
public class SysAliRoleController extends BaseController {
    @Autowired
    private ISysAliRoleService sysAliRoleService;

    /**
     * 查询阿里登录角色绑定列表
     */
    @PreAuthorize("@ss.hasPermi('pay:alirole:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAliRole sysAliRole) {
        startPage();
        List<SysAliRole> list = sysAliRoleService.selectSysAliRoleList(sysAliRole);
        return getDataTable(list);
    }

    /**
     * 导出阿里登录角色绑定列表
     */
    @PreAuthorize("@ss.hasPermi('pay:alirole:export')")
    @Log(title = "阿里登录角色绑定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAliRole sysAliRole) throws IOException {
        List<SysAliRole> list = sysAliRoleService.selectSysAliRoleList(sysAliRole);
        ExcelUtil<SysAliRole> util = new ExcelUtil<SysAliRole>(SysAliRole.class);
        util.exportExcel(response, list, "alirole");
    }

    /**
     * 获取阿里登录角色绑定详细信息
     */
    @PreAuthorize("@ss.hasPermi('pay:alirole:query')")
    @GetMapping(value = "/{aliId}")
    public AjaxResult getInfo(@PathVariable("aliId") Long aliId) {
        return AjaxResult.success(sysAliRoleService.selectSysAliRoleById(aliId));
    }

    /**
     * 新增阿里登录角色绑定
     */
    @PreAuthorize("@ss.hasPermi('pay:alirole:add')")
    @Log(title = "阿里登录角色绑定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAliRole sysAliRole) {
        return toAjax(sysAliRoleService.insertSysAliRole(sysAliRole));
    }

    /**
     * 修改阿里登录角色绑定
     */
    @PreAuthorize("@ss.hasPermi('pay:alirole:edit')")
    @Log(title = "阿里登录角色绑定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAliRole sysAliRole) {
        return toAjax(sysAliRoleService.updateSysAliRole(sysAliRole));
    }

    /**
     * 删除阿里登录角色绑定
     */
    @PreAuthorize("@ss.hasPermi('pay:alirole:remove')")
    @Log(title = "阿里登录角色绑定", businessType = BusinessType.DELETE)
    @DeleteMapping("/{aliIds}")
    public AjaxResult remove(@PathVariable Long[] aliIds) {
        return toAjax(sysAliRoleService.deleteSysAliRoleByIds(aliIds));
    }
}
